<?php

/**
 * transfer the mutation
 * to AP table
 *
 * fetch the amount
 */
$CLFetchers->fetchDtlInvoice($Db,
                             $jobId,
                             $SourceDb->fetchValue("srcDbDtlIvcSupplier"),
                             $nDetail,
                             $lstDetail);

$CLFetchers->fetchSubInvoice($Db,
                             $jobId,
                             $SourceDb->fetchValue("srcDbSubIvcSupplier"),
                             $nSubDetail,
                             $lstSubDetail);

if($isApprove){

  /**
   * write to transaction mutation
   */
  for($iRow = 0; $iRow < $nSubDetail ; $iRow++){

    $CLFetchers->fetchLastMutationNo($Db,
                                     $lstSubDetail["REFERENCE"][0],
                                     $SourceDb->fetchValue("srcDbMutIvcSupplier"),
                                     $subDtlNo);

    $txDate   = " TO_DATE('".date("d-m-Y",
                                  strtotime($lstSubDetail["TR_DATE"][$iRow]))."',
                          'dd-mm-YYYY') ";

    $dueDate  = " TO_DATE('".date("d-m-Y",
                                  strtotime($lstSubDetail["DUE_DATE"][$iRow]))."',
                          'dd-mm-YYYY') ";

    /**
     * since this is an payment out
     * then the amount should be (-)
     */
    $amount = $lstSubDetail["AMOUNT"][0] * -1;

    $values = "  ".$periode.",    ".
              " '".$lstHeader["SUPPLIER_CUSTOMER"][0]."', ".
              " '".$lstSubDetail["REFERENCE"][$iRow]."',      ".
              " '".$refId."',   ".
              "  ".$hdrDate.",  ".
              "  ".$txDate.",   ".
              "  ".$dueDate.",  ".
              "  ".$txType.",   ".
              "  ".$amount." ,  ".
              "  ".$subDtlNo."  ";

    $CLHandlers->insToMutInvoice($Db,
                                 "SUPPLIER_CODE",
                                 $values,
                                 $SourceDb->fetchValue("srcDbMutIvcSupplier"));
  }
}else{

  for($iRow = 0; $iRow < $nSubDetail ; $iRow++){


  }
}

if($isApprove){

  /**
   * write to header of cash bank source
   * the MUT_CASH_BANK_DETAIL
   */
  $CLFetchers->fetchLstDataDetail($Db,
                                  $jobId,
                                  $SourceDb->fetchValue("srcDbDtl"),
                                  $nDetail,
                                  $lstDetail);

  $CLFetchers->fetchLastMutCbDtlNo($Db,
                                   $_SESSION["sysPeriode"],
                                   $SourceDb->fetchValue("srcDbMutCbDtl"),
                                   $mutCbDtlNo);

  $values = " '".$refId."',                     ".
            " '".$lstHeader["C_B_CODE"][0]."',  ".
            "  ".$mutCbDtlNo.",   ".
            "  ".$periode.",    ".
            "  ".$hdrDate.",    ".
            " '".$lstHeader["SUPPLIER_CUSTOMER"][0]."', ".
            "  ".$txType.",                     ".
            " '".$lstHeader["CURRENCY"][0]."',  ".
            "  ".$lstHeader["RATE"][0].",       ".
            "  ".$lstDetail["TOT_AMOUNT"][0].", ".
            "  ".$lstDetail["TOT_NET"][0]."     ";

  $CLHandlers->insToMutCbDtl($Db,
                             $values,
                             $SourceDb->fetchValue("srcDbMutCbDtl"));
}else{

  $CHandlers->dbEntDelete($Db,
                          $jobId,
                          $SourceDb->fetchValue("srcDbMutCbDtl"));
}

?>